#ifndef __NETCOMM_NETCHATSESSION_H__
#define __NETCOMM_NETCHATSESSION_H__

#include "netchatter.h"
#include "netchatroom.h"

#include <boost/asio/ip/tcp.hpp>

#include <memory>

class NetChatSession
  : public NetChatter,
    public std::enable_shared_from_this<NetChatSession>
{
public:
    typedef boost::asio::ip::tcp::socket TcpSocket;

    NetChatSession(NetChatRoom &);

    TcpSocket& socket();

    void start();
    void deliver(const NetChatMsg &);
    void handle_read_header(const boost::system::error_code &);
    void handle_read_body(const boost::system::error_code &);
    void handle_write(const boost::system::error_code &);

private:
    TcpSocket    m_socket;
    NetChatRoom& m_room;
    NetChatMsg   m_read_msg;
    chat_message_queue m_write_msgs;
};

typedef std::shared_ptr<NetChatSession> NetChatSessionPtr;

#endif //__NETCOMM_NETCHATSESSION_H__
